//
// Created by Wesley on 25-2-6.
//

#ifndef SOLUTION167_H
#define SOLUTION167_H
#include <vector>
using namespace std;

class solution167 {
    public:
    vector<int> twoSum(vector<int>& numbers, int target);
};

inline vector<int> solution167::twoSum(vector<int>& numbers, int target) {
    // 第一个索引位置
    int left = 0;
    // 最后一个索引位置
    int right = numbers.size() - 1;

    while (left < right) {
        const int temp = numbers[left] + numbers[right];
        if (temp == target) {
            vector<int> result;
            result.push_back(left+1);
            result.push_back(right+1);
            return result;
        }

        if (temp > target) {
            right--;
        }else{
            left ++;
        }
    }
    return {};
}
#endif //SOLUTION167_H
